<template>
  <div ref="chartRef" style="width: 600px; height: 400px"></div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
import useCategoryRates from './useCategoryRates'

const chartRef = ref<HTMLDivElement | null>(null)
const { categoryRates } = useCategoryRates()

onMounted(() => {
  if (chartRef.value) {
    const myChart = echarts.init(chartRef.value)
    const option = {
      title: {
        text: '日志数量分布',
        left: 'center',
      },
      tooltip: {
        trigger: 'item',
      },
      legend: {
        orient: 'vertical',
        left: 'left',
      },
      series: [
        {
          name: '日志数量',
          type: 'pie',
          radius: '50%',
          data: categoryRates.value,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    }
    myChart.setOption(option)
  }
})
</script>
